package com.hfh.io;

import org.junit.Test;

import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;

public class WriterDemo {
    @Test
    public void test3(){
        try(Writer writer = new FileWriter("file\\b.txt")) {

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void test2(){
        try(Writer writer = new FileWriter("file\\b.txt")) {
            String str = "我爱北京天安门";
//            writer.write(str);
            writer.write(str,0,5);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void test1(){
        try(Writer writer = new FileWriter("file\\b.txt")) {
            char[] arr = "我爱北京天安门".toCharArray();
//            writer.write(arr);
            writer.write(arr,0,5);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void test(){
        try(Writer writer = new FileWriter("file\\b.txt",true)) {
            writer.write('\u597d');
            writer.write(97);
            writer.write(37650);
            writer.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
